package com.kkb.hbase.mr.demo5GroupComparator;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 对同一分区内的OrderID进行分组，保证相同的OrderID进入同一组，每个组调用一次reduce逻辑
 */
public class OrderGroup extends WritableComparator {

    /**
     * 使用默认构造器，定义了传入的JavaBean的类型
     */
    public OrderGroup(){
        super(OrderBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean a1 = (OrderBean) a;
        OrderBean a2 = (OrderBean) b;
        //按照orderid进行比较，相同的orderID划分到同一个组里面 调用一次reduce逻辑
        return a1.getOrderId().compareTo(a2.getOrderId());
    }
}
